package Servlets;

import java.io.IOException;
import java.util.List;
import javaBeans.Film;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import Services.GetFilmService;

/**
 * Servlet implementation class GetFilmServlet
 */
@WebServlet("/GetFilmServlet")
public class GetFilmServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

	/**
	 * @see HttpServlet#HttpServlet()
	 */
	public GetFilmServlet() {
		super();
		// TODO Auto-generated constructor stub
	}

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		System.out.println("got to getfilmService");
		HttpSession session = request.getSession();
		GetFilmService getFilmService = new GetFilmService();
		List<Film> filmList = getFilmService.getFilms(); // gets all films.
		for (Film film : filmList) {
			System.out.println(film.getName());
			
		}
		session.setAttribute("filmlist", filmList);
		String param = request.getParameter("r");
		if (param != null) {
			response.sendRedirect("Pages/films.jsp?r=" + param);
		} else {
			response.sendRedirect("Pages/films.jsp");
		}
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {

	}
}
